package com.college.resource.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.CampusInformationType;
import com.college.common.pojo.dto.resource.AddCampusInformationTypeDTO;
import com.college.common.pojo.dto.resource.QueryCampusInformationTypeDTO;
import com.college.common.pojo.dto.resource.UpdateCampusInformationTypeDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.mapper.CampusInformationTypeMapper;
import com.college.resource.service.CampusInformationTypeService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 校园资讯分类 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class CampusInformationTypeServiceImpl extends ServiceImpl<CampusInformationTypeMapper, CampusInformationType> implements CampusInformationTypeService {
    @Autowired
    private CampusInformationTypeMapper campusInformationTypeMapper;

    @Override
    public List<CampusInformationType> queryList(QueryCampusInformationTypeDTO queryCampusInformationTypeDTO) {
        return campusInformationTypeMapper.queryList(queryCampusInformationTypeDTO);
    }

    @Override
    public List<CampusInformationType> queryListPage(QueryCampusInformationTypeDTO queryCampusInformationTypeDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return campusInformationTypeMapper.queryList(queryCampusInformationTypeDTO);
    }

    @Override
    public CommonResult<String> addCampusInformationType(AddCampusInformationTypeDTO addCampusInformationTypeDTO) {
        return this.save(addCampusInformationTypeDTO)? CommonResult.success("校园资讯分类新增成功") : CommonResult.failed("校园资讯分类新增失败");
    }

    @Override
    public CommonResult<String> updateCampusInformationType(UpdateCampusInformationTypeDTO updateCampusInformationTypeDTO) {
        CampusInformationType campusInformationType = ObjectUtil.objectCopyProperties(updateCampusInformationTypeDTO, CampusInformationType.class);
        return this.updateById(campusInformationType) ? CommonResult.success("校园资讯分类修改成功") : CommonResult.failed("校园资讯分类修改失败");
    }
}
